In [1]:
import os
import numpy as np
import pandas as pd

import matplotlib.pyplot as plt

%matplotlib inline

from sklearn.cross_validation import train_test_split
from sklearn.metrics import mean_squared_error

Load the ratings


In [68]:
path = os.path.join(os.getcwd(),"..","datasets", "ml1m", "ratings.dat")
ratings = pd.read_table(path, sep="::",  names=["UserID", 'MovieID', 'Rating', 'Timestamp'], engine='python', header = None, index_col=['UserID', 'MovieID']).drop('Timestamp', axis=1)

Load the movie data


In [78]:
path = os.path.join(os.getcwd(), "..","datasets", "ml1m", "movies.dat")
movies = pd.read_table(path, sep="::",  names=["MovieID", 'Title', 'Genre'], header = None, engine='python')

Load the user data


In [4]:
path = os.path.join(os.getcwd(), "..","datasets", "ml1m", "users.dat")
users = pd.read_table(path, sep="::", names=["UserID", "Gender", "Age", "Occupation", 'Zip-code'], header = None, engine='python')

Functions for adding metadata


In [5]:
def add_gender_metadata(movies):
    genders = [[0,'Male',''],[0,'Female','']]
    mov_id = movies['MovieID'].max()
    for g in genders:
        mov_id = mov_id + 1
        g[0] = mov_id
    return movies.append(pd.DataFrame(genders, columns = ['MovieID', "Title","Genre"]), ignore_index=True)

def add_age_metadata(movies):
    ages = [[0,"Under 18", ""], [0,"18-24", ""], [0,"25-34", ""], [0,"35-44", ""], 
        [0,"45-49", ""], [0,"50-55", ""], [0,"56+", ""]]
    mov_id = movies['MovieID'].max()
    for a in ages:
        mov_id = mov_id + 1
        a[0] = mov_id
    return movies.append(pd.DataFrame(ages, columns = ['MovieID', "Title","Genre"]), ignore_index=True)

def add_gender_age_metadata(movies):
    gender_ages = [[0,"Male",""], [0,"Male - Under 18", ""], [0,"Male - 18-24", ""], [0,"Male - 25-34", ""], 
            [0,"Male - 35-44", ""], [0,"Male - 45-49", ""], [0,"Male - 50-55", ""], [0,"Male - 56+", ""],
            [0,"Female",""], [0,"Female - Under 18", ""], [0,"Female - 18-24", ""], [0,"Female - 25-34", ""], 
            [0,"Female - 35-44", ""], [0,"Female - 45-49", ""], [0,"Female - 50-55", ""], [0,"Female - 56+", ""]]

    mov_id = movies['MovieID'].max()

    for ma in gender_ages:
        mov_id = mov_id + 1
        ma[0] = mov_id
                  
    return movies.append(pd.DataFrame(gender_ages, columns = ['MovieID', "Title","Genre"]), ignore_index=True)

def get_gender_item(user_row):
    if(user_row["Gender"] == "M"):
        return "Male"
    elif(user_row["Gender"] == "F"):
        return "Female"

def get_age_item(user_row):
    if(user_row["Age"] == 1):
        return "Under 18"
    elif(user_row["Age"] == 18):
        return "18-24"
    elif(user_row["Age"] == 25):
        return "25-34"
    elif(user_row["Age"] == 35):
        return "35-44"
    elif(user_row["Age"] == 45):
        return "45-49"
    elif(user_row["Age"] == 50):
        return "50-55"
    elif(user_row["Age"] == 56):
        return "56+"
    else:
        return None

def get_gender_age_item(user_row):
    item = get_gender_item(user_row)
    if get_age_item(user_row):
        item += ' - ' + get_age_item(user_row)
    return item

Get a set of all the genres


In [6]:
genres = set()
for row in movies.iterrows():
    for genre in row[1]['Genre'].split('|'):
        genres.add(genre)

Create a corpus


In [92]:
include_metadata = 'none' #gender/age/gender+age/gender-age
metadata_weight = 1.0

path = os.path.join(os.getcwd(), "..","datasets", "ml1m", "movies.dat")
movies = pd.read_table(path, sep="::",  names=["MovieID", 'Title', 'Genre'], header = None, engine='python')

if include_metadata == 'gender':
    movies = add_gender_metadata(movies)
elif include_metadata == 'age':
    movies = add_age_metadata(movies)
elif include_metadata == 'gender+age':
    movies = add_gender_metadata(movies)
    movies = add_age_metadata(movies)
elif include_metadata == 'gender-age':
    movies = add_gender_age_metadata(movies)

path = os.path.join(os.getcwd(),"..","datasets", "ml1m.dat")
fo = open(path, "w")

line = str(movies.shape[0]) + ' '
for movie in movies.iterrows():
    line += str(movie[0]) + ':' + str(1.0) + ' '
line += '\n'
fo.write(line)

for user in users.iterrows():
    user_index = user[0]
    user_id = user[1]['UserID']
    
    count = 0
    doc = ''
    
    if include_metadata == 'gender':
        item = movies[(movies["Title"] == get_gender_item(users.loc[user_index]))].index[0]
        doc  += str(item) + ":" + str(metadata_weight) + ' '
        count += 1
    elif include_metadata == 'age':
        item = movies[(movies["Title"] == get_age_item(users.loc[user_index]))].index[0]
        doc  += str(item) + ":" + str(metadata_weight) + ' '
        count += 1
    elif include_metadata == 'gender+age':
        item = movies[(movies["Title"] == get_gender_item(users.loc[user_index]))].index[0]
        doc  += str(item) + ":" + str(metadata_weight) + ' '
        item = movies[(movies["Title"] == get_age_item(users.loc[user_index]))].index[0]
        doc  += str(item) + ":" + str(metadata_weight) + ' '
        count += 2
    elif include_metadata == 'gender-age':
        item = movies[(movies["Title"] == get_gender_age_item(users.loc[user_index]))].index[0]
        doc  += str(item) + ":" + str(metadata_weight) + ' '
        count += 1
    
    user_ratings = ratings.loc[user_id]
#     mean = user_ratings.mean()
#     std = user_ratings.std()
#     user_ratings = user_ratings.subtract(mean)
#     if std != 0:
#         user_ratings = user_ratings.divide(std)
#     mini = np.abs(user_ratings.min()) + 1.0
#     user_ratings = user_ratings.add(mini).round()

    rated = movies[movies["MovieID"].isin(user_ratings.index)].drop(['Title','Genre'],1)  
    user_ratings = user_ratings.merge(rated, left_index=True, right_on='MovieID')

    for movie_index in user_ratings.index:
        doc = doc + str(movie_index) + ':' + str(1.0) + " "
        count += 1
    doc = str(count) + " " + doc + "\n"

    fo.write(doc)
fo.close()

In [79]:
movies


Out[79]:
MovieID Title Genre IndexVal
0 1 Toy Story (1995) Animation|Children's|Comedy 0
1 2 Jumanji (1995) Adventure|Children's|Fantasy 1
2 3 Grumpier Old Men (1995) Comedy|Romance 2
3 4 Waiting to Exhale (1995) Comedy|Drama 3
4 5 Father of the Bride Part II (1995) Comedy 4
5 6 Heat (1995) Action|Crime|Thriller 5
6 7 Sabrina (1995) Comedy|Romance 6
7 8 Tom and Huck (1995) Adventure|Children's 7
8 9 Sudden Death (1995) Action 8
9 10 GoldenEye (1995) Action|Adventure|Thriller 9
10 11 American President, The (1995) Comedy|Drama|Romance 10
11 12 Dracula: Dead and Loving It (1995) Comedy|Horror 11
12 13 Balto (1995) Animation|Children's 12
13 14 Nixon (1995) Drama 13
14 15 Cutthroat Island (1995) Action|Adventure|Romance 14
15 16 Casino (1995) Drama|Thriller 15
16 17 Sense and Sensibility (1995) Drama|Romance 16
17 18 Four Rooms (1995) Thriller 17
18 19 Ace Ventura: When Nature Calls (1995) Comedy 18
19 20 Money Train (1995) Action 19
20 21 Get Shorty (1995) Action|Comedy|Drama 20
21 22 Copycat (1995) Crime|Drama|Thriller 21
22 23 Assassins (1995) Thriller 22
23 24 Powder (1995) Drama|Sci-Fi 23
24 25 Leaving Las Vegas (1995) Drama|Romance 24
25 26 Othello (1995) Drama 25
26 27 Now and Then (1995) Drama 26
27 28 Persuasion (1995) Romance 27
28 29 City of Lost Children, The (1995) Adventure|Sci-Fi 28
29 30 Shanghai Triad (Yao a yao yao dao waipo qiao) ... Drama 29
... ... ... ... ...
3853 3923 Return of the Fly (1959) Horror|Sci-Fi 3853
3854 3924 Pajama Party (1964) Comedy 3854
3855 3925 Stranger Than Paradise (1984) Comedy 3855
3856 3926 Voyage to the Bottom of the Sea (1961) Adventure|Sci-Fi 3856
3857 3927 Fantastic Voyage (1966) Adventure|Sci-Fi 3857
3858 3928 Abbott and Costello Meet Frankenstein (1948) Comedy|Horror 3858
3859 3929 Bank Dick, The (1940) Comedy 3859
3860 3930 Creature From the Black Lagoon, The (1954) Horror 3860
3861 3931 Giant Gila Monster, The (1959) Horror|Sci-Fi 3861
3862 3932 Invisible Man, The (1933) Horror|Sci-Fi 3862
3863 3933 Killer Shrews, The (1959) Horror|Sci-Fi 3863
3864 3934 Kronos (1957) Sci-Fi 3864
3865 3935 Kronos (1973) Horror 3865
3866 3936 Phantom of the Opera, The (1943) Drama|Thriller 3866
3867 3937 Runaway (1984) Sci-Fi|Thriller 3867
3868 3938 Slumber Party Massacre, The (1982) Horror 3868
3869 3939 Slumber Party Massacre II, The (1987) Horror 3869
3870 3940 Slumber Party Massacre III, The (1990) Horror 3870
3871 3941 Sorority House Massacre (1986) Horror 3871
3872 3942 Sorority House Massacre II (1990) Horror 3872
3873 3943 Bamboozled (2000) Comedy 3873
3874 3944 Bootmen (2000) Comedy|Drama 3874
3875 3945 Digimon: The Movie (2000) Adventure|Animation|Children's 3875
3876 3946 Get Carter (2000) Action|Drama|Thriller 3876
3877 3947 Get Carter (1971) Thriller 3877
3878 3948 Meet the Parents (2000) Comedy 3878
3879 3949 Requiem for a Dream (2000) Drama 3879
3880 3950 Tigerland (2000) Drama 3880
3881 3951 Two Family House (2000) Drama 3881
3882 3952 Contender, The (2000) Drama|Thriller 3882

3883 rows × 4 columns

Load beta


In [21]:
path = os.path.join(os.getcwd(), "..", "param", "ml1m", "beta.dat")
beta = pd.read_table(path, sep=" ", header = None).apply(np.exp, 1)

In [23]:
num_words_to_print = 30
for topic in range(beta.shape[0]):
    top_words = beta.loc[topic].sort_values(ascending=False).index
    genre_count = pd.DataFrame(np.zeros(len(genres)), index = genres)
    
    topic_str = ''
    topic_str += '%2d'%topic
    topic_str += ': '
    
    weights = False
    
    for i in range(num_words_to_print):
        movie_name =  movies.loc[top_words[i]]["Title"]
        movie_name = movie_name[:-7] if movie_name[-1] == ')' else movie_name
        topic_str += movie_name 
        if weights:
            topic_str += '(' + str(beta.loc[topic][top_words[i]].round(3)) +  ')'
        topic_str += ' | '
    print(topic_str)
    print()


 0: Grifters, The | Third Man, The | In the Heat of the Night | Bananas | Last Picture Show, The | Outlaw Josey Wales, The | Hairspray | Ruthless People | Shadow of a Doubt | Fatal Attraction | Pink Floyd - The Wall | St. Elmo's Fire | Chungking Express | Searchers, The | Popeye | My Own Private Idaho | Last Man Standing | Gentleman's Agreement | Body Snatchers | Oliver! | Jules and Jim (Jules et Jim) | Tin Drum, The (Blechtrommel, Die) | Boys on the Side | Killing Fields, The | Seven Beauties (Pasqualino Settebellezze) | Walk in the Clouds, A | Hamlet | Hocus Pocus | Alien� | Blue Juice | 

 1: Sleeper | Brazil | Night of the Living Dead | 2001: A Space Odyssey | Clockwork Orange, A | Babe: Pig in the City | Adventures of Buckaroo Bonzai Across the 8th Dimension, The | Shallow Grave | James and the Giant Peach | Them! | Mighty Aphrodite | Nikita (La Femme Nikita) | End of the Affair, The | Killing, The | Pitch Black | Raging Bull | On the Town | Paths of Glory | Mission to Mars | Pushing Tin | Menace II Society | Song of the South | Palm Beach Story, The | Once Were Warriors | Captain Horatio Hornblower | Pacific Heights | Dick | Grumpier Old Men | Hand That Rocks the Cradle, The | Screamers | 

 2: Sliding Doors | Wings of Desire (Der Himmel �ber Berlin) | Enchanted April | Carrie | Pretty in Pink | Everyone Says I Love You | Six Degrees of Separation | Indian in the Cupboard, The | Drop Dead Gorgeous | Runaway Train | Absolute Power | Kiss the Girls | Sanjuro | Barefoot in the Park | Frances | Blue Sky | City Slickers II: The Legend of Curly's Gold | Requiem for a Dream | Brassed Off | Paulie | Love and Basketball | Cube | Kids | Mr. Nice Guy | Mad Dog Time | I Shot a Man in Vegas | Breathing Room | Female Perversions | Santa with Muscles | Hype! | 

 3: Breaking Away | Cabaret | Cinema Paradiso | American in Paris, An | Klute | Top Hat | Guys and Dolls | Crimes and Misdemeanors | Nashville | Walkabout | Bicycle Thief, The (Ladri di biciclette) | Diva | Man for All Seasons, A | 39 Steps, The | Meatballs | Miller's Crossing | Love and Death on Long Island | Walk on the Moon, A | Next Stop, Wonderland | Shall We Dance? | Burnt By the Sun (Utomlyonnye solntsem) | Death Wish | Dancer in the Dark | Lost Horizon | Color of Paradise, The (Rang-e Khoda) | Dante's Peak | Coming Home | For a Few Dollars More | Limbo | Microcosmos (Microcosmos: Le peuple de l'herbe) | 

 4: Manchurian Candidate, The | Charade | Ideal Husband, An | Repo Man | Midnight Run | Body Heat | Purple Rose of Cairo, The | Plan 9 from Outer Space | Persuasion | Killer, The (Die xue shuang xiong) | Dreamlife of Angels, The (La Vie r�v�e des anges) | Take the Money and Run | Nightmare on Elm Street, A | Prick Up Your Ears | Texas Chainsaw Massacre, The | Omega Man, The | Under Siege | Happy, Texas | Get Shorty | King of New York | Species | Tao of Steve, The | Belle de jour | Swept Away (Travolti da un insolito destino nell'azzurro mare d'Agosto) | Looking for Richard | Paris Was a Woman | Breathing Room | Mad Dog Time | Anna | Female Perversions | 

 5: Wild Bunch, The | Everest | Muriel's Wedding | Rumble in the Bronx | Liar Liar | Thirteenth Floor, The | Addams Family, The | White Men Can't Jump | Tin Cup | Honeymoon in Vegas | Bamba, La | Spanking the Monkey | Flirting With Disaster | Meet Joe Black | Michael Collins | Mrs. Miniver | Swiss Family Robinson | Singles | Pit and the Pendulum | Gulliver's Travels | Nurse Betty | About Last Night... | Batman & Robin | Varsity Blues | Alien� | Blue Juice | Kids of Survival | I'm Not Rappaport | Anna | Paris Was a Woman | 

 6: Bug's Life, A | Toy Story | Toy Story 2 | Sixth Sense, The | Female | Ghostbusters | Shakespeare in Love | Babe | Who Framed Roger Rabbit? | Tarzan | Aladdin | Mulan | Erin Brockovich | 25-34 | Elizabeth | American Pie | Galaxy Quest | Princess Bride, The | Adventures in Babysitting | Lion King, The | Breakfast Club, The | Little Mermaid, The | 18-24 | Antz | Chicken Run | E.T. the Extra-Terrestrial | Hercules | Iron Giant, The | Office Space | American Beauty | 

 7: Monty Python and the Holy Grail | Fish Called Wanda, A | Annie Hall | Raising Arizona | This Is Spinal Tap | Young Frankenstein | Animal House | Monty Python's Life of Brian | Butch Cassidy and the Sundance Kid | Princess Bride, The | Stand by Me | Caddyshack | Harold and Maude | M*A*S*H | Deliverance | Do the Right Thing | Breakfast Club, The | Manhattan Murder Mystery | Moonstruck | Key Largo | Broadcast News | Lord of the Flies | Being There | Unforgiven | Rosencrantz and Guildenstern Are Dead | Henry V | Cool Hand Luke | My Life as a Dog (Mitt liv som hund) | Golden Child, The | Blazing Saddles | 

 8: Shining, The | Birds, The | Blair Witch Project, The | Psycho | Evil Dead II (Dead By Dawn) | Poltergeist | What Ever Happened to Baby Jane? | Scream | Halloween | Titanic | Omen, The | Doors, The | Bride of Frankenstein | American Werewolf in London, An | Dracula | Amistad | 2 Days in the Valley | Karate Kid, Part II, The | Amityville Horror, The | Shaft | Eraserhead | Celebration, The (Festen) | Mommie Dearest | ...And Justice for All | Impostors, The | Madonna: Truth or Dare | Voyage to the Bottom of the Sea | I'm Not Rappaport | Anna | My Life as a Dog (Mitt liv som hund) | 

 9: Scent of a Woman | Name of the Rose, The | True Grit | Postman Always Rings Twice, The | Copycat | Giant | Splendor in the Grass | East of Eden | Thin Blue Line, The | And the Band Played On | Matilda | Cookie's Fortune | Skulls, The | Romeo Must Die | Near Dark | Breathing Room | Paris Was a Woman | 56+ | Anna | Mad Dog Time | Blue Juice | Kids of Survival | Alien� | American Werewolf in London, An | I'm Not Rappaport | Santa with Muscles | Female Perversions | Amityville 3-D | Hype! | Parallel Sons | 

10: Deer Hunter, The | Victor/Victoria | Sleepy Hollow | Winslow Boy, The | Henry: Portrait of a Serial Killer | Englishman Who Went Up a Hill, But Came Down a Mountain, The | 400 Blows, The (Les Quatre cents coups) | Towering Inferno, The | Children of Paradise (Les enfants du paradis) | Escape from L.A. | Wayne's World 2 | Paris Was a Woman | Alien� | Kids of Survival | Blue Juice | American Werewolf in London, An | Amityville 1992: It's About Time | Amityville 3-D | I'm Not Rappaport | Anna | Mad Dog Time | Breathing Room | Amityville: A New Generation | Female Perversions | Santa with Muscles | Hype! | Parallel Sons | I Shot a Man in Vegas | When Harry Met Sally... | Until the End of the World (Bis ans Ende der Welt) | 

11: Star Trek: The Wrath of Khan | Jaws | Star Wars: Episode V - The Empire Strikes Back | Terminator, The | Star Wars: Episode IV - A New Hope | Alien | Die Hard | E.T. the Extra-Terrestrial | Aliens | Raiders of the Lost Ark | Rocky | Great Escape, The | Ben-Hur | Blues Brothers, The | Gods Must Be Crazy, The | French Connection, The | Poseidon Adventure, The | Runaway Bride | Sting, The | Lethal Weapon | Ladyhawke | Back to the Future | Blade Runner | Boat, The (Das Boot) | Killing Fields, The | Predator | Superman II | Messenger: The Story of Joan of Arc, The | Bottle Rocket | Planet of the Apes | 

12: North by Northwest | Boys Don't Cry | Hoop Dreams | Player, The | Notorious | Midnight Cowboy | Welcome to the Dollhouse | Bridge on the River Kwai, The | Blue Velvet | Piano, The | Double Jeopardy | Commitments, The | Boat, The (Das Boot) | Thin Red Line, The | Election | Rebecca | Women on the Verge of a Nervous Breakdown | Taxi Driver | Madness of King George, The | Waiting for Guffman | Killing Fields, The | Unbearable Lightness of Being, The | L.A. Story | Little Voice | Friday | Topsy-Turvy | Apostle, The | Bob Roberts | Love Bug, The | Bullets Over Broadway | 

13: Negotiator, The | Mickey Blue Eyes | Irma la Douce | Jeremiah Johnson | Wolf | Shaft | Hot Shots! Part Deux | Patriot, The | My Fellow Americans | Paradise Lost: The Child Murders at Robin Hood Hills | 28 Days | Passion Fish | Soapdish | Deep Rising | Gone in 60 Seconds | Character (Karakter) | Paris Was a Woman | Breathing Room | Santa with Muscles | Mad Dog Time | Female Perversions | Anna | I'm Not Rappaport | 56+ | Hype! | Parallel Sons | I Shot a Man in Vegas | When Harry Met Sally... | Until the End of the World (Bis ans Ende der Welt) | Paris, Texas | 

14: Apocalypse Now | Network | Stalag 17 | Dog Day Afternoon | Jackie Brown | Midnight Express | Bound | Heavenly Creatures | Opposite of Sex, The | Marathon Man | Year of Living Dangerously | Glengarry Glen Ross | Best Years of Our Lives, The | Ice Storm, The | Big Night | All About My Mother (Todo Sobre Mi Madre) | Christmas Carol, A | Crumb | Lolita | Koyaanisqatsi | Devil in a Blue Dress | Thing From Another World, The | Murder, My Sweet | Farewell My Concubine | Bronx Tale, A | Sleepers | Serpico | Carlito's Way | Ninotchka | Bring It On | 

15: Austin Powers: International Man of Mystery | Mystery Science Theater 3000: The Movie | Central Station (Central do Brasil) | Presidio, The | Heartbreak Ridge | Three Colors: White | Net, The | Three Colors: Blue | Sid and Nancy | Scream 3 | Mallrats | Mumford | Friday the 13th | Naked Gun: From the Files of Police Squad!, The | Haunting, The | 7th Voyage of Sinbad, The | Canadian Bacon | Horseman on the Roof, The (Hussard sur le toit, Le) | F/X 2 | Breathing Room | My Life as a Dog (Mitt liv som hund) | Blue Juice | Forbidden Planet | I'm Not Rappaport | Anna | Paris Was a Woman | Field of Dreams | Man Who Would Be King, The | Mad Dog Time | Butch Cassidy and the Sundance Kid | 

16: Hunt for Red October, The | Fugitive, The | Total Recall | Fifth Element, The | Men in Black | Matrix, The | Braveheart | Jurassic Park | Terminator 2: Judgment Day | Speed | Face/Off | Die Hard | Clear and Present Danger | Enemy of the State | Saving Private Ryan | Rock, The | Patriot Games | Last of the Mohicans, The | Tomorrow Never Dies | Die Hard 2 | In the Line of Fire | Star Trek VI: The Undiscovered Country | Thomas Crown Affair, The | Gattaca | Armageddon | Mission: Impossible | Heat | Die Hard: With a Vengeance | Male | 35-44 | 

17: Stuart Little | Con Air | Breaking the Waves | Longest Day, The | Night to Remember, A | Single White Female | Replacement Killers, The | Old Man and the Sea, The | Malice | You Can't Take It With You | Man Without a Face, The | Operation Condor 2 (Longxiong hudi) | Prophecy, The | Swimming with Sharks | Last Detail, The | Journey of Natty Gann, The | Universal Soldier | How to Make an American Quilt | What Dreams May Come | City Hall | Loaded Weapon 1 | Clay Pigeons | Hollow Man | Liberty Heights | Assault on Precinct 13 | Paris Was a Woman | Female Perversions | Killing Fields, The | Anna | Pink Floyd - The Wall | 

18: English Patient, The | Postino, Il (The Postman) | 50-55 | My Left Foot | Limey, The | Red Violin, The (Le Violon rouge) | Midnight in the Garden of Good and Evil | Primary Colors | Mis�rables, Les | Lolita | Ghost Dog: The Way of the Samurai | Spawn | Beach, The | Angus | Wes Craven's New Nightmare | Drowning Mona | Home Alone 2: Lost in New York | Crying Game, The | Field of Dreams | Alien� | Kids of Survival | Blue Juice | I'm Not Rappaport | Forbidden Planet | Anna | Paris Was a Woman | Breathing Room | When Harry Met Sally... | Mad Dog Time | Until the End of the World (Bis ans Ende der Welt) | 

19: Hoosiers | City Lights | Alien� | Parent Trap, The | Never Been Kissed | Fantasia 2000 | Natural, The | Bodyguard, The | It Could Happen to You | Story of Us, The | I.Q. | One Fine Day | Any Given Sunday | First Knight | Flatliners | She's the One | Killing Zoe | Four Rooms | Angela's Ashes | Jingle All the Way | Bed of Roses | Big Momma's House | Female Perversions | Anna | Paris Was a Woman | I'm Not Rappaport | Breathing Room | My Life as a Dog (Mitt liv som hund) | Mad Dog Time | Field of Dreams | 

20: Fisher King, The | Muppet Movie, The | Mr. Mom | Willy Wonka and the Chocolate Factory | Wonder Boys | Real Genius | Don Juan DeMarco | Little Shop of Horrors, The | Jungle Book, The | You've Got Mail | Muppets Take Manhattan, The | Taming of the Shrew, The | Godzilla (Gojira) | Scrooged | Mask, The | Great Muppet Caper, The | Fletch | Hook | Corrina, Corrina | Lady Eve, The | Buffy the Vampire Slayer | Back to School | Better Off Dead... | Ghostbusters II | Christmas Vacation | Muppet Treasure Island | Mission, The | First Wives Club, The | Man with Two Brains, The | River Wild, The | 

21: Indiana Jones and the Last Crusade | Star Wars: Episode VI - Return of the Jedi | Star Wars: Episode I - The Phantom Menace | Independence Day (ID4) | Male | Forrest Gump | Indiana Jones and the Temple of Doom | Jurassic Park | Star Wars: Episode V - The Empire Strikes Back | Untouchables, The | Air Force One | Star Trek: Generations | Raiders of the Lost Ark | Princess Bride, The | American President, The | Lethal Weapon 2 | Right Stuff, The | Dances with Wolves | GoldenEye | Romancing the Stone | Lethal Weapon | Lost World: Jurassic Park, The | Glory | Outbreak | Maverick | As Good As It Gets | Mummy, The | League of Their Own, A | Terms of Endearment | Men in Black | 

22: Exorcist, The | Papillon | Frankenstein | True Romance | Great Santini, The | Full Metal Jacket | Hard-Boiled (Lashou shentan) | All the King's Men | To Live (Huozhe) | Pillow Book, The | Guns of Navarone, The | Man in the Iron Mask, The | Cop Land | Man Who Knew Too Much, The | River Runs Through It, A | View to a Kill, A | Affair to Remember, An | Other Sister, The | 42 Up | Smilla's Sense of Snow | Living Out Loud | Me, Myself and Irene | Cemetery Man (Dellamorte Dellamore) | Miracle on 34th Street | Godfather: Part II, The | Beverly Hills Cop III | Butch Cassidy and the Sundance Kid | Forbidden Planet | Paris Was a Woman | Breathing Room | 

23: Peter Pan | Fantasia | Pinocchio | 101 Dalmatians | Sleeping Beauty | Charlotte's Web | Yellow Submarine | 13th Warrior, The | Alice in Wonderland | Return of the Pink Panther, The | Sabrina | Robin Hood | Field of Dreams | Doctor Dolittle | Winnie the Pooh and the Blustery Day | Waterworld | Rescuers, The | Fanny and Alexander | Father of the Bride | Emerald Forest, The | Lost in Space | Tom Jones | Far and Away | Way We Were, The | Karate Kid, The | Dead Men Don't Wear Plaid | Rising Sun | Bedknobs and Broomsticks | Bad Seed, The | Tommy | 

24: Diner | General's Daughter, The | Deep Impact | Great Dictator, The | Dead Calm | Affliction | Red Sorghum (Hong Gao Liang) | Secret of Roan Inish, The | Down by Law | Reds | Peggy Sue Got Married | Mighty, The | Stepford Wives, The | North Dallas Forty | Mercury Rising | East is East | Nine 1/2 Weeks | Palmetto | Program, The | Rocky II | Decline of Western Civilization, The | Strawberry and Chocolate (Fresa y chocolate) | Anna | Paris Was a Woman | Breathing Room | I'm Not Rappaport | Hype! | Mad Dog Time | Female Perversions | Santa with Muscles | 

25: Jumanji | Back to the Future Part III | Ever After: A Cinderella Story | NeverEnding Story, The | Soylent Green | 20,000 Leagues Under the Sea | All Quiet on the Western Front | Santa Clause, The | Jackie Chan's First Strike | Breaker Morant | Steel Magnolias | Night of the Comet | Jaws 2 | William Shakespeare's Romeo and Juliet | Falcon and the Snowman, The | Borrowers, The | Space Jam | Nutty Professor, The | Jack | Dreamscape | Way of the Gun, The | King Kong | Blue Juice | I'm Not Rappaport | Anna | Paris Was a Woman | Breathing Room | Mad Dog Time | Female Perversions | Cat People | 

26: Thunderball | Ordinary People | Secret Garden, The | In the Name of the Father | Gaslight | Wings of the Dove, The | Immortal Beloved | Little Princess, A | Mighty Ducks, The | Rescuers Down Under, The | Grand Illusion (Grande illusion, La) | Buena Vista Social Club | My Science Project | Dick Tracy | Reindeer Games | Sullivan's Travels | Parent Trap, The | Cape Fear | I'm Not Rappaport | Paris Was a Woman | Breathing Room | Mad Dog Time | Female Perversions | Nightmare on Elm Street, A | Santa with Muscles | Hype! | Nosferatu (Nosferatu, eine Symphonie des Grauens) | Parallel Sons | I Shot a Man in Vegas | When Harry Met Sally... | 

27: Sense and Sensibility | Breakfast at Tiffany's | Witness | Top Gun | Much Ado About Nothing | Female | Out of Africa | Four Weddings and a Funeral | Shakespeare in Love | Room with a View, A | Moonstruck | Emma | Pretty Woman | Risky Business | Splash | Little Mermaid, The | While You Were Sleeping | My Best Friend's Wedding | Grease | Notting Hill | Ghost | Romancing the Stone | Pale Rider | When We Were Kings | To Be or Not to Be | Quick and the Dead, The | Keeping the Faith | Dirty Dancing | Best in Show | Quest for Fire | 

28: Fight Club | Clerks | Eyes Wide Shut | Rushmore | Being John Malkovich | Edward Scissorhands | South Park: Bigger, Longer and Uncut | Run Lola Run (Lola rennt) | 18-24 | Adventures of Priscilla, Queen of the Desert, The | Big Lebowski, The | Magnolia | American Beauty | Gods and Monsters | Dogma | City of Lost Children, The | Romy and Michele's High School Reunion | Nightmare Before Christmas, The | Delicatessen | Three Kings | Go | Lock, Stock & Two Smoking Barrels | Princess Mononoke, The (Mononoke Hime) | Austin Powers: The Spy Who Shagged Me | Mariachi, El | Trainspotting | Roger & Me | Get Shorty | Howards End | Pi | 

29: 12 Angry Men | Old Yeller | Three Amigos! | Dazed and Confused | She's Gotta Have It | Horse Whisperer, The | Dinosaur | City of Angels | Days of Thunder | One Crazy Summer | Blowup | Stepmom | Snake Eyes | Angels and Insects | She's All That | Shadow, The | Center Stage | Mouse Hunt | Ace Ventura: When Nature Calls | Santa with Muscles | Anna | Amityville 1992: It's About Time | Field of Dreams | American Werewolf in London, An | Alien� | Kids of Survival | Man Who Would Be King, The | Blue Juice | I'm Not Rappaport | Butch Cassidy and the Sundance Kid | 

30: Clueless | Wrong Trousers, The | Full Monty, The | Pleasantville | Close Shave, A | Quiz Show | Wedding Singer, The | Groundhog Day | Wallace & Gromit: The Best of Aardman Animation | Ed Wood | Truman Show, The | Auntie Mame | Searching for Bobby Fischer | Local Hero | Wayne's World | Election | Where Eagles Dare | Jacob's Ladder | Toy Story 2 | Cruel Intentions | Swingers | Zero Effect | There's Something About Mary | Bloodsport | Kolya | Office Space | Contender, The | Grosse Pointe Blank | Empire Records | Drunken Master (Zui quan) | 

31: Parenthood | Platoon | Sixteen Candles | Stripes | Truth About Cats & Dogs, The | Creature Comforts | Tommy Boy | Pee-wee's Big Adventure | Teenage Mutant Ninja Turtles | Re-Animator | Vacation | Married to the Mob | Roger & Me | Analyze This | Peacemaker, The | Sweet and Lowdown | Good Morning, Vietnam | Maurice | Weird Science | Johnny Mnemonic | Peeping Tom | Kids in the Hall: Brain Candy | Billy Madison | Escape from the Planet of the Apes | Brady Bunch Movie, The | Naked Gun 2 1/2: The Smell of Fear, The | Crooklyn | Fear of a Black Hat | Running Man, The | Child's Play | 

32: To Catch a Thief | Apartment, The | Arthur | Heaven Can Wait | Grumpy Old Men | Odd Couple, The | Suspicion | Mutiny on the Bounty | Shampoo | Final Destination | Taking of Pelham One Two Three, The | SLC Punk! | EDtv | Lost Highway | Picture Perfect | All Dogs Go to Heaven | Mad Dog Time | Anna | Blue Juice | I'm Not Rappaport | Santa with Muscles | Breathing Room | Paris Was a Woman | Female Perversions | 56+ | Hype! | Parallel Sons | I Shot a Man in Vegas | Kids of Survival | Until the End of the World (Bis ans Ende der Welt) | 

33: Maltese Falcon, The | Strangers on a Train | Double Indemnity | Touch of Evil | Bringing Up Baby | Raisin in the Sun, A | Lady Vanishes, The | It Happened One Night | Sunset Blvd. (a.k.a. Sunset Boulevard) | Ran | Red Rock West | Three Days of the Condor | Seventh Seal, The (Sjunde inseglet, Det) | Yojimbo | To Kill a Mockingbird | Run Silent, Run Deep | Lost Weekend, The | Casablanca | Asphalt Jungle, The | Citizen Kane | Blob, The | Event Horizon | Blood Simple | Conversation, The | Lord of Illusions | Arrival, The | Blown Away | Kentucky Fried Movie, The | Until the End of the World (Bis ans Ende der Welt) | Hype! | 

34: Male | Godfather, The | Fargo | Silence of the Lambs, The | Schindler's List | L.A. Confidential | Shawshank Redemption, The | 25-34 | Sixth Sense, The | One Flew Over the Cuckoo's Nest | Pulp Fiction | Godfather: Part II, The | Saving Private Ryan | Usual Suspects, The | Graduate, The | American Beauty | GoodFellas | Star Wars: Episode IV - A New Hope | Taxi Driver | Professional, The (a.k.a. Leon: The Professional) | Star Wars: Episode V - The Empire Strikes Back | Sling Blade | 45-49 | Shakespeare in Love | Raiders of the Lost Ark | Insider, The | Casablanca | 35-44 | Verdict, The | French Connection, The | 

35: Wizard of Oz, The | Female | Mary Poppins | E.T. the Extra-Terrestrial | Babe | Snow White and the Seven Dwarfs | Like Water for Chocolate (Como agua para chocolate) | Gone with the Wind | Strictly Ballroom | Casablanca | To Kill a Mockingbird | Lady and the Tramp | Sound of Music, The | Doctor Zhivago | West Side Story | African Queen, The | My Fair Lady | It's a Wonderful Life | Close Encounters of the Third Kind | Dangerous Liaisons | Crying Game, The | Cinderella | Thelma & Louise | Driving Miss Daisy | Eat Drink Man Woman | Five Easy Pieces | Man Who Would Be King, The | Amadeus | Gandhi | Singin' in the Rain | 

36: Thing, The | Fly, The | Westworld | Strange Days | Forbidden Planet | No Way Out | Heavy Metal | To Die For | Nineteen Eighty-Four | Barbarella | Philadelphia | Picnic at Hanging Rock | Stop Making Sense | In & Out | Cape Fear | eXistenZ | Lord of the Rings, The | Evita | Hidden, The | Fright Night | In the Company of Men | Nutty Professor, The | I Shot Andy Warhol | Phantasm | Rambo: First Blood Part II | Celluloid Closet, The | Addams Family Values | Bachelor Party | Long Walk Home, The | Brother from Another Planet, The | 

37: Manhattan | Cape Fear | Rosemary's Baby | Misery | Tender Mercies | Goodbye Girl, The | Mosquito Coast, The | Spellbound | From Dusk Till Dawn | Falling Down | Rebel Without a Cause | American Psycho | Twin Falls Idaho | Hurricane, The | Pecker | Man Who Knew Too Much, The | Only You | Safe | Black Sheep | Road Trip | Small Time Crooks | Mildred Pierce | Very Bad Things | Marnie | Half Baked | Magnum Force | Forbidden Planet | Field of Dreams | I'm Not Rappaport | Anna | 

38: Things to Do in Denver when You're Dead | Twelfth Night | Christine | Grand Canyon | Jean de Florette | Summer of Sam | Color of Money, The | Last Action Hero | Thirty-Two Short Films About Glenn Gould | Freeway | Frighteners, The | Fletch Lives | Murder in the First | My Blue Heaven | Dirty Work | Mona Lisa | Farinelli: il castrato | Children of Heaven, The (Bacheha-Ye Aseman) | Great Race, The | Out-of-Towners, The | Breathing Room | Amityville 1992: It's About Time | American Werewolf in London, An | Alien� | Kids of Survival | Blue Juice | I'm Not Rappaport | Anna | Albino Alligator | Paris Was a Woman | 

39: Around the World in 80 Days | Cliffhanger | I Know What You Did Last Summer | Some Kind of Wonderful | Birdy | Lifeboat | Outsiders, The | Scream 2 | For Love of the Game | Cutting Edge, The | War Room, The | Butcher Boy, The | Mother | Mulholland Falls | Nick of Time | Clockers | Barcelona | Henry Fool | Crocodile Dundee II | Honey, I Blew Up the Kid | Free Willy | Get on the Bus | Felicia's Journey | When Harry Met Sally... | Alien� | Butch Cassidy and the Sundance Kid | Kids of Survival | Paris, Texas | Blue Juice | Until the End of the World (Bis ans Ende der Welt) | 

40: Big Chill, The | Manon of the Spring (Manon des sources) | U-571 | Red Dawn | Candidate, The | Brothers McMullen, The | Force 10 from Navarone | History of the World: Part I | Breakdown | Rules of Engagement | European Vacation | Cry in the Dark, A | Beavis and Butt-head Do America | What's Love Got to Do with It? | Weekend at Bernie's | Coyote Ugly | Paris Was a Woman | Blue Juice | Kids of Survival | Alien� | American Werewolf in London, An | I'm Not Rappaport | Anna | 56+ | Breathing Room | Mad Dog Time | Female Perversions | Santa with Muscles | Hype! | Parallel Sons | 

41: Rear Window | Vertigo | Big Sleep, The | Laura | Invasion of the Body Snatchers | Dial M for Murder | Grapes of Wrath, The | Spartacus | Mr. Smith Goes to Washington | Bonnie and Clyde | Metropolis | Color Purple, The | Hard Day's Night, A | Thin Man, The | Meet Me in St. Louis | U.S. Marshalls | To Sir with Love | Boys from Brazil, The | African Queen, The | Smoke Signals | Hope Floats | 8 1/2 | Haunting, The | Shop Around the Corner, The | Antonia's Line (Antonia) | Tampopo | Postman, The | To Wong Foo, Thanks for Everything! Julie Newmar | Arsenic and Old Lace | Time Code | 

42: What's Eating Gilbert Grape | Duck Soup | Chasing Amy | M | Hudsucker Proxy, The | Joy Luck Club, The | Instinct | Dolores Claiborne | Help! | Powder | Age of Innocence, The | People vs. Larry Flynt, The | Funny Face | Pump Up the Volume | Night on Earth | Croupier | Metropolitan | Licence to Kill | One True Thing | White Squall | Pawnbroker, The | He Got Game | Great Expectations | Jesus' Son | Man Who Would Be King, The | Anna | Paris Was a Woman | I'm Not Rappaport | Blue Juice | Breathing Room | 

43: Alien | Close Encounters of the Third Kind | Aliens | Blade Runner | 2001: A Space Odyssey | Terminator, The | Time Bandits | Star Trek IV: The Voyage Home | Matrix, The | Twelve Monkeys | Superman | Army of Darkness | Star Wars: Episode IV - A New Hope | Abyss, The | Rocky Horror Picture Show, The | Highlander | Back to the Future | Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb | Robocop | Cocoon | Day the Earth Stood Still, The | Logan's Run | Terminator 2: Judgment Day | Star Trek III: The Search for Spock | Ghostbusters | Stargate | Dune | Planet of the Apes | Back to the Future Part II | Predator | 

44: Simple Plan, A | Dead Zone, The | Some Folks Call It a Sling Blade | Tie Me Up! Tie Me Down! | Nobody's Fool | Last Temptation of Christ, The | Tin Men | Howling, The | Damien: Omen II | Fear and Loathing in Las Vegas | Mummy, The | Alive | Craft, The | Wild Wild West | Of Mice and Men | Vampires | Frenzy | Great Mouse Detective, The | Odessa File, The | Place in the Sun, A | Cable Guy, The | Hellraiser | Condorman | Beautiful Girls | Soldier's Story, A | Naked Gun 33 1/3: The Final Insult | Bachelor, The | Stranger Than Paradise | Evil Dead II (Dead By Dawn) | Breathing Room | 

45: Talented Mr. Ripley, The | X-Files: Fight the Future, The | Sneakers | Misery | Payback | Devil's Advocate, The | Bone Collector, The | Game, The | Arlington Road | Sommersby | Civil Action, A | Tombstone | Austin Powers: The Spy Who Shagged Me | Mrs. Doubtfire | Stir of Echoes | Crimson Tide | Godfather: Part III, The | American Pie | Courage Under Fire | Entrapment | Desperately Seeking Susan | Wild Things | Frequency | Stigmata | Return to Me | Tora! Tora! Tora! | Big Daddy | Deep Blue Sea | Ransom | Time to Kill, A | 

46: Chinatown | Lawrence of Arabia | American Graffiti | Producers, The | Philadelphia Story, The | Little Big Man | Some Like It Hot | Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb | Arsenic and Old Lace | Roman Holiday | Psycho | Sting, The | Cool Hand Luke | Little Shop of Horrors | M*A*S*H | Young Frankenstein | Streetcar Named Desire, A | Sabrina | Sweet Hereafter, The | Treasure of the Sierra Madre, The | His Girl Friday | Guess Who's Coming to Dinner | Citizen Kane | Singin' in the Rain | Hud | When Harry Met Sally... | Harvey | All About Eve | Blade Runner | Wizard of Oz, The | 

47: Good, The Bad and The Ugly, The | Goldfinger | Dirty Dozen, The | Dr. No | Seven Samurai (The Magnificent Seven) (Shichinin no samurai) | Butch Cassidy and the Sundance Kid | From Russia with Love | African Queen, The | King Kong | Fistful of Dollars, A | Glory | Adventures of Robin Hood, The | Live and Let Die | For Your Eyes Only | Crow, The | Three Colors: Red | First Blood | Jagged Edge | Eraser | Conan the Barbarian | Kagemusha | Soldier | Disclosure | Spy Who Loved Me, The | Ipcress File, The | Police Academy | Mad Max 2 (a.k.a. The Road Warrior) | Vanya on 42nd Street | On Her Majesty's Secret Service | Man with the Golden Gun, The | 

48: Christmas Story, A | Groundhog Day | Ferris Bueller's Day Off | Good Will Hunting | Dead Poets Society | Bull Durham | Big | When Harry Met Sally... | Apollo 13 | Dave | Rain Man | Life Is Beautiful (La Vita � bella) | Airplane! | Wag the Dog | Jerry Maguire | Titanic | Shawshank Redemption, The | Waking Ned Devine | There's Something About Mary | My Cousin Vinny | Rob Roy | Say Anything... | Heathers | Back to the Future | Cider House Rules, The | Awakenings | Leaving Las Vegas | Dead Again | Raise the Red Lantern | Fast Times at Ridgemont High | 

49: Modern Times | My Favorite Year | General, The | Born Yesterday | Playing by Heart | Gay Divorcee, The | Bell, Book and Candle | My Man Godfrey | Rounders | Night Shift | Fabulous Baker Boys, The | Battleship Potemkin, The (Bronenosets Potyomkin) | Fly Away Home | East-West (Est-ouest) | Object of My Affection, The | Runaway | Female Perversions | Santa with Muscles | 56+ | Mad Dog Time | Breathing Room | Hype! | Anna | I'm Not Rappaport | Blue Juice | Paris Was a Woman | When Harry Met Sally... | Parallel Sons | I Shot a Man in Vegas | Alien� | 


In [134]:
path = os.path.join(os.getcwd(), "..", "param", "ml1m", "theta.dat")
theta = pd.read_table(path, sep=" ", header = None).apply(np.exp, 1)

In [147]:
chosen_one = 765
users.loc[chosen_one]


Out[147]:
UserID          766
Gender            F
Age              25
Occupation        7
Zip-code      95128
Name: 765, dtype: object

In [148]:
most_popular = beta.multiply(theta.loc[chosen_one], 0).sum().sort_values(ascending=False).index
pop_str = ''
for i in range(100):
    movie_name =  movies.loc[most_popular[i]]["Title"]
    movie_name = movie_name[:-7] if movie_name[-1] == ')' else movie_name
    pop_str += movie_name + ' | '
print(pop_str)


Princess Bride, The | Monty Python and the Holy Grail | Back to the Future | Fish Called Wanda, A | Raising Arizona | Animal House | Butch Cassidy and the Sundance Kid | Caddyshack | Romancing the Stone | E.T. the Extra-Terrestrial | Big | Breakfast Club, The | Ferris Bueller's Day Off | Stand by Me | Blazing Saddles | Young Frankenstein | Trading Places | Dangerous Liaisons | Wizard of Oz, The | Four Weddings and a Funeral | Bull Durham | Full Monty, The | Christmas Story, A | Groundhog Day | High Fidelity | In the Line of Fire | Splash | Star Wars: Episode IV - A New Hope | Spaceballs | Pretty Woman | Unforgiven | Broadcast News | Crying Game, The | Say Anything... | Shining, The | Heathers | Good Morning, Vietnam | Much Ado About Nothing | Sense and Sensibility | Big Chill, The | When Harry Met Sally... | Amadeus | Clueless | Natural, The | Rain Man | Mary Poppins | Midnight in the Garden of Good and Evil | Taxi Driver | To Catch a Thief | Little Mermaid, The | Dead Poets Society | Airplane! | My Best Friend's Wedding | Fast Times at Ridgemont High | Moonstruck | Ghost | Beetlejuice | Parenthood | Notting Hill | Muppet Movie, The | Ben-Hur | Raiders of the Lost Ark | Driving Miss Daisy | Interview with the Vampire | Indiana Jones and the Last Crusade | Casablanca | Net, The | Little Big Man | Three Amigos! | Star Wars: Episode V - The Empire Strikes Back | Raging Bull | While You Were Sleeping | Do the Right Thing | Vertigo | Gandhi | Grease | Chinatown | Henry V | Toy Story | Crimes and Misdemeanors | Emma | Godfather: Part III, The | Patton | Arthur | Titanic | Wrong Trousers, The | Platoon | Wayne's World | Sting, The | Ed Wood | Gods Must Be Crazy, The | Being There | Clockwork Orange, A | Chariots of Fire | Ladyhawke | Sound of Music, The | Men in Black | Clue | Deliverance | Working Girl | 

In [137]:
most_popular = beta.sum().sort_values(ascending=False).index
pop_str = ''
for i in range(100):
    movie_name =  movies.loc[most_popular[i]]["Title"]
    movie_name = movie_name[:-7] if movie_name[-1] == ')' else movie_name
    pop_str += movie_name + ' | '
print(pop_str)


Male - 25-34 | Casablanca | Godfather, The | This Is Spinal Tap | Star Wars: Episode IV - A New Hope | American Beauty | Godfather: Part II, The | Vertigo | Taxi Driver | Princess Bride, The | Back to the Future | L.A. Confidential | Pulp Fiction | Chinatown | Ghostbusters | Being John Malkovich | Star Wars: Episode V - The Empire Strikes Back | Toy Story | North by Northwest | Full Metal Jacket | Alien | E.T. the Extra-Terrestrial | Who Framed Roger Rabbit? | Terminator, The | Indiana Jones and the Last Crusade | Raiders of the Lost Ark | Austin Powers: The Spy Who Shagged Me | Babe | Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb | Professional, The (a.k.a. Leon: The Professional) | Manchurian Candidate, The | Witness | Sixth Sense, The | Men in Black | Groundhog Day | Bug's Life, A | Dirty Dozen, The | Gladiator | Star Wars: Episode VI - Return of the Jedi | Usual Suspects, The | Apocalypse Now | Godfather: Part III, The | Jaws | Full Monty, The | Wizard of Oz, The | Fargo | Romancing the Stone | Game, The | Butch Cassidy and the Sundance Kid | American Pie | Shakespeare in Love | Matrix, The | Brazil | Blade Runner | Forrest Gump | Saving Private Ryan | Spaceballs | Toy Story 2 | Psycho | Annie Hall | Lethal Weapon | English Patient, The | Female - 25-34 | Dave | Monty Python and the Holy Grail | Life Is Beautiful (La Vita � bella) | Sneakers | Do the Right Thing | High Fidelity | Silence of the Lambs, The | Fugitive, The | Shawshank Redemption, The | Twelve Monkeys | Speed | Clockwork Orange, A | Out of Africa | Birds, The | Schindler's List | Dangerous Liaisons | Player, The | GoldenEye | Grifters, The | Boat, The (Das Boot) | Abyss, The | Big | Terminator 2: Judgment Day | Blues Brothers, The | Moonstruck | Ferris Bueller's Day Off | Rock, The | Robocop | American President, The | Aladdin | Lion King, The | In the Line of Fire | Highlander | Die Hard | Male - 35-44 | Shining, The | Keeping the Faith | 

In [ ]:


In [ ]:
path = os.path.join(os.getcwd(), "..", "param", "ml1m", "theta.dat")
gamma = pd.read_table(path, sep=" ", header = None)
gamma.loc[8].argmax()

In [ ]:
for gen_doc in gender_docs:
    topic = gender_docs[gen_doc]
    
    top_words = beta.loc[topic].sort_values(ascending=False).index
    genre_count = pd.DataFrame(np.zeros(len(genres)), index = genres)

    if topic < 10:
        print topic, " :" ,
    else:
        print topic , ":" , 
        
    print gen_doc, " : "

    for i in xrange(50):
        movie_name =  movies.loc[top_words[i]]["Title"]
        if movie_name[-1] == ')':
            print movie_name[:-7], ' |', 
        else:
            print movie_name, ' |', 

    print
    print

In [ ]:
topic = 6
top_words = beta.loc[topic].sort_values(ascending=False).index
genre_count = pd.DataFrame(np.zeros(len(genres)), index = genres)

if topic < 10:
    print topic, " :" ,
else:
    print topic , ":" , 

for i in xrange(200):
    movie_name =  movies.loc[top_words[i]]["Title"]
    if movie_name[-1] == ')':
        print movie_name[:-7], '(', beta.loc[topic][top_words[i]].round(3),  ') |', 
    else:
        print movie_name, ' |', 

print
print

In [ ]:
fig, ax = plt.subplots(figsize=(20,10))

ind = np.arange(len(genres)) 
width = 1.0

topic = 29

num_items = 50

top_words = beta.loc[topic].sort_values(ascending=False).index
genre_count = pd.DataFrame(np.zeros(len(genres)), index = genres)

for i in xrange(num_items):
    for gn in movie_names.loc[movies[top_words[i]]][1].split('|'):
        genre_count.loc[gn] = genre_count.loc[gn] + 1

ax.bar(ind, genre_count.values, width=width, color='r')
ind = ind + width

ax.set_ylabel('Count')
ax.set_xlabel('Genre')
ax.set_title('Genre Counts per Topic')
ax.set_xticks(ind-0.5)
xlabels = []
for item in genres:
    xlabels.append(item)
ax.set_xticklabels(xlabels)
plt.show()

for i in xrange(num_items):
        print movie_names.loc[movies[top_words[i]]][0][:-7], ' |',

In [ ]: